﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class SudokuRegion : System.Web.UI.UserControl
{
    private int row;
    private int column;

    public string Row
    {
        get
        {
            return this.row.ToString();
        }
        set
        {
            this.row = int.Parse(value);
        }
    }

    public string Column
    {
        get
        {
            return this.column.ToString();
        }
        set
        {
            this.column = int.Parse(value);
        }
    }

    private void BindToSquare(SudokuSquare square)
    {
        square.RegionColumn = this.Column;
        square.RegionRow = this.Row;
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        System.Diagnostics.Debug.WriteLine(
            String.Format("- Rendering region {0},{1}", row + 1, column + 1));

        if (!Page.IsPostBack)
        {
            if (Row != null)
            {
                this.region.Attributes["data-row"] = this.Row.ToString();
            }
            if (Column != null)
            {
                this.region.Attributes["data-column"] = this.Column.ToString();
            }
        }

        BindToSquare(this.Square1);
        BindToSquare(this.Square2);
        BindToSquare(this.Square3);
        BindToSquare(this.Square4);
        BindToSquare(this.Square5);
        BindToSquare(this.Square6);
        BindToSquare(this.Square7);
        BindToSquare(this.Square8);
        BindToSquare(this.Square9);
    }
}